Skip to content

fix(ios): fail fast when a session's simulator no longer exists - #4696

Merged
thymikee merged 2 commits into
callstack:mainfrom
xiatiandeairen:fix/ios-missing-simulator-fast-fail
Nov 19, 2026
Merged

thymikee merged 2 commits into
callstack:mainfrom
xiatiandeairen:fix/ios-missing-simulator-fast-fail

Conversation

@xiatiandeairen

@xiatiandeairen xiatiandeairen commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A session keeps booted from its open. After an external pool deletes the simulator, the next runner start skipped every check. xcodebuild then waited out its 20 s destination timeout and returned COMMAND_FAILED with a hint to delete the shared runner cache.

The runner start now runs one simctl list devices -j to confirm that a booted session simulator still exists. If it does not, the start fails with DEVICE_NOT_FOUND, names the UDID, and suggests close. The check follows the shape of refreshSessionDeviceIfNeeded in the daemon and is loaded lazily. It is skipped when this process saw the simulator Booted moments ago (the existing booted memo). A listing that cannot be read never refuses a start (CONSERVATIVE:).

6 files, +158/-6, 77 of them tests.

Fixes #4687.

Validation

Head bfbf2503c on base aa600e980.

  • check:quick passed. apple-runner tests: 984 pass. The new tests fail against base runner-session.ts.
  • check:affected --run --head bfbf2503c (exactCommit): format, lint, typecheck, layering, fallow, build and vitest-related passed. unit failed only in test/repo-guards/android-sdk-setup-action.test.ts (2 tests). They fail the same way on aa600e980 on this host, where a local Android SDK path leaks into the expected path.
  • iOS 27.2 simulator deleted after open. Next snapshot -i: base took 23.3 s and returned COMMAND_FAILED with the cache hint. Head took 0.6–1.0 s and returned DEVICE_NOT_FOUND with details.deviceId. close succeeds. open time is unchanged (12.4 s head, 12.7 s base).

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff

A session keeps the booted fact from its open, so a runner restart after
the simulator was deleted skipped every check and let xcodebuild wait out
its 20 s destination timeout. The error then blamed the shared runner
cache. Before the launch, one simctl listing confirms the simulator is
still there, unless this process saw it booted moments ago. A missing
simulator fails with DEVICE_NOT_FOUND naming its UDID.
@thymikee

Copy link
Copy Markdown
Member

Thanks for the fix. At bfbf250 the check itself looks right, but the wiring that fixes #4687 has no regression test, so I would add one before merge.

All five tests in runner-simulator-presence.test.ts call assertBootedSimulatorStillListed directly. The reported failure is a runner start (startRunnerSessionWithLease -> ensureBootedIfNeeded with device.booted === true) on a deleted simulator, and no test reaches that route. Deleting the dynamic import and call at runner-session.ts:876-878, or flipping device.booted, keeps every test green. The PR body says the new tests fail against base, but that is true only because the module is missing, not because the behavior fails at base. runner-session.test.ts already starts a booted simulator session (around line 291) and asserts which simctl calls ran, so the harness exists. Please add one test there that starts a runner for a booted simulator, with simctl list devices -j omitting the udid and the memo cold. It should assert the start rejects with code DEVICE_NOT_FOUND, with details.deviceId set and dispatched no, and that no xcodebuild launch happens (mockRunCmdBackground not called). Keep one or two of the unit cases and drop the rest as duplicates of the route test.

Not blocking, and you can take or leave these: simctlListingHasDevice in runner-simulator-presence.ts:56 re-parses list devices -j that readSimulatorBootState and readSimctlDeviceState in platform-apple already own, so the owner could expose the unlisted-versus-unreadable distinction and the port could bind that instead; the memo skip adds a port member, a binding, a test default, a test and a lazy import to save about 0.7 s on a runner start that already takes several seconds, so consider dropping it unless a measurement shows the open path regresses; and a few comments (the lazy-import note, the two CONSERVATIVE: comments, the module doc block) can shrink to one sentence each, while the new ios_runner_startup_simulator_listing_failed phase has no test assertion.

CI is green. The one check reported, and its check:affected note names unit failures only in test/repo-guards/android-sdk-setup-action.test.ts, which this diff does not touch. There are no conflicts. The 23.3 s versus 0.6-1.0 s timings and the unchanged open time come from the PR body. Before merge, the route-level regression test above needs to land.

The presence check had unit tests only, so removing its call from
ensureBootedIfNeeded kept every test green. A runner-session readiness
test now starts a runner for a booted simulator that the simctl listing
omits and asserts DEVICE_NOT_FOUND with the udid, dispatched no, no
cache-wiping hint, and no xcodebuild launch. The unit cases that
duplicated it are dropped; the ones that must not refuse a start stay.
@xiatiandeairen

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I pushed e213127 with the route-level regression test.

The route test. runner-session-readiness.test.ts now has runner session start refuses a booted session simulator the listing no longer has. It calls ensureRunnerSession for a booted simulator. The simctl list devices -j listing omits the udid, and the memo is cold (the test host default). The test asserts that:

  • the start rejects with DEVICE_NOT_FOUND;
  • details.deviceId is the udid;
  • dispatched is no;
  • the hint does not point at apple-runner/derived or clean:xcuitest;
  • mockRunCmdBackground is never called, so xcodebuild does not launch.

I put the test in runner-session-readiness.test.ts, not in runner-session.test.ts. With the test added, runner-session.test.ts reached 1481 lines and failed max-lines (the limit is 1456). The readiness file already covers pre-launch start checks and has the same harness.

It fails without the wiring. When I delete the assertBootedSimulatorStillListed(device, signal) call in ensureBootedIfNeeded, the new test fails. With the call restored, it passes.

Unit cases. I dropped "missing from the listing is refused" and "still listed passes", because the route test duplicates them. Three cases stay. Each one pins a start that must not be refused, and the route test does not reach these:

  • an unreadable listing (exit 1, non-JSON output, or a thrown error);
  • a cancelled listing, which reports the cancellation;
  • the memo hit.

The memo test stays as long as the memo stays.

Checks run locally: the apple-runner tests pass (983), lint passes, and the layering tests (483/483) and scan pass.

Not done in this push: the non-blocking items. These are binding the platform-apple listing owner instead of re-parsing, dropping the memo, shrinking the comments, and asserting ios_runner_startup_simulator_listing_failed. Dropping the memo would change production code. If you want it gone, say so and I will remove it together with its port member and its test.

@thymikee

Copy link
Copy Markdown
Member

This is ready. At e213127 the route-level regression test through ensureRunnerSession is in place, so the ask from the earlier review (#4696 (comment)) is met. It checks DEVICE_NOT_FOUND, the deviceId, that nothing was dispatched, and that runCmdBackground is never called. The duplicate unit cases are gone, as requested.

Not blocking: the header comment in runner-simulator-presence.test.ts says the refusal is covered in runner-session.test.ts, but the route test is in runner-session-readiness.test.ts. You can fix that name or leave it.

The Smoke Tests run failed in the Android emulator keyboard step (agent-device keyboard status --platform android in waitForKeyboardVisible). This PR touches only Apple runner code and tests, so the failure looks unrelated. The branch also predates the Android e2e stabilization in #4716. The failed job has been re-run; a rebase onto main also works if it fails again. There are no conflicts.

The PR body still lists the old head, file count and "new tests fail against base". The live-device numbers come from the earlier head and still apply, since this change is test-only.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 19, 2026
@thymikee
thymikee merged commit 886f204 into callstack:main Nov 19, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: a command on a session whose simulator was deleted waits ~22 s and suggests deleting the shared runner cache

2 participants